home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 6 / Amiga Format AFCD06 (Nov 1996, Issue 90).iso / screenplay / utility / game_patches_for_hd / marblemadness / contrib / mmpatch.c next >
C/C++ Source or Header  |  1996-07-27  |  3KB  |  124 lines

  1. /*
  2.  * Patch Marble Madness.
  3.  *
  4.  * Usage: cd <Marble Madness disk>
  5.  *        mmpatch
  6.  *
  7.  * > removes protection on c/xxx, c/zzz, c/MarbleMadness!.dat
  8.  *   - 2.0+ actually checks for read protection
  9.  *
  10.  * > applies standard patch to c/xxx (taken from QuickCopy)
  11.  *   - changes some conditional branches to unconditional
  12.  *   - inserts some immediate constants
  13.  *   
  14.  * > applies patch to c/zzz
  15.  *   - original reads some values from low memory and from the Task struct,
  16.  *     expecting the third nybble to be 0xFC (i.e., pointers into ROM);
  17.  *     512k ROMs are at 0xF8xxxx, so this no longer works
  18.  *   - patch uses immediate values instead
  19.  *
  20.  * Derek Noonburg
  21.  * derekn@ece.cmu.edu
  22.  * 29-April-93
  23.  *
  24.  * Modified on 27-July-96 by JF Fabre (the patch did not work because of a
  25.  * DOS programming error. Derek, you hack good, but please test your patches!
  26.  * Fortunately you provided the source code :-) )
  27.  */
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <exec/types.h>
  32. #include <dos/dos.h>
  33. #include <proto/dos.h>
  34.  
  35. #define XXXNAME "MarbleMadness!:c/xxx"
  36. #define ZZZNAME "MarbleMadness!:c/zzz"
  37. #define DATNAME "MarbleMadness!:c/MarbleMadness!.dat"
  38. #define SIGNAME "MarbleMadness!:c/sigfile"
  39. #define XXXLEN 6116
  40. #define ZZZLEN 4948
  41.  
  42. int
  43. main()
  44. {
  45.     BPTR f;
  46.     static UBYTE buf[XXXLEN];
  47.     UWORD *wbuf = (UWORD *)buf;
  48.  
  49.     SetProtection(XXXNAME, 0);
  50.     SetProtection(ZZZNAME, 0);
  51.     SetProtection(DATNAME, 0);
  52.     SetProtection(SIGNAME, 0);
  53.  
  54.     if (!(f = Open(XXXNAME, MODE_OLDFILE))) {
  55.         fprintf(stderr, "Can't open file\n");
  56.         exit(1);
  57.     }
  58.     Read(f, buf, XXXLEN);
  59.     buf[0x1bc] = 0x25;
  60.     buf[0x1c0] = 0x9b;
  61.     buf[0x1c4] = 0x6e;
  62.     buf[0x1c6] = 0x83;
  63.     buf[0x1c7] = 0x78;
  64.     buf[0x336] = 0x40;
  65.     buf[0x337] = 0xad;
  66.     buf[0x386] = 0xaf;
  67.     buf[0x387] = 0x3e;
  68.     buf[0x38b] = 0x43;
  69.     buf[0x38e] = 0x53;
  70.     buf[0x38f] = 0xb1;
  71.  
  72.     Close(f);
  73.  
  74.     if (!(f = Open(XXXNAME, MODE_NEWFILE))) {
  75.         fprintf(stderr, "Can't create file\n");
  76.         exit(1);
  77.     }
  78.  
  79.     Write(f, buf, XXXLEN);
  80.     Close(f);
  81.  
  82.     if (!(f = Open(ZZZNAME, MODE_OLDFILE))) {
  83.         fprintf(stderr, "Can't open file\n");
  84.         exit(1);
  85.     }
  86.     Read(f, buf, ZZZLEN);
  87.     wbuf[0x82a] = 0x2f3c;   /* move.l #fc000000,-(a7) */
  88.     wbuf[0x82b] = 0x00fc;
  89.     wbuf[0x82c] = 0x0000;
  90.     wbuf[0x82d] = 0x4e71;   /* nop */
  91.     wbuf[0x82e] = 0x4e71;   /* nop */
  92.     wbuf[0x82f] = 0x4e71;   /* nop */
  93.     wbuf[0x830] = 0x4e71;   /* nop */
  94.     wbuf[0x848] = 0x2f3c;   /* move.l #fc000000,-(a7) */
  95.     wbuf[0x849] = 0x00fc;
  96.     wbuf[0x84a] = 0x0000;
  97.     wbuf[0x84b] = 0x4e71;   /* nop */
  98.     wbuf[0x864] = 0x2f3c;   /* move.l #fc000000,-(a7) */
  99.     wbuf[0x865] = 0x00fc;
  100.     wbuf[0x866] = 0x0000;
  101.     wbuf[0x867] = 0x4e71;   /* nop */
  102.     wbuf[0x873] = 0x2f3c;   /* move.l #fc000000,-(a7) */
  103.     wbuf[0x874] = 0x00fc;
  104.     wbuf[0x875] = 0x0000;
  105.     wbuf[0x876] = 0x4e71;   /* nop */
  106.     wbuf[0x87e] = 0x2f3c;   /* move.l #fc000000,-(a7) */
  107.     wbuf[0x87f] = 0x00fc;
  108.     wbuf[0x880] = 0x0000;
  109.     wbuf[0x881] = 0x4e71;   /* nop */
  110.     Close(f);
  111.  
  112.     if (!(f = Open(ZZZNAME, MODE_NEWFILE))) {
  113.         fprintf(stderr, "Can't create file\n");
  114.         exit(1);
  115.     }
  116.  
  117.     Write(f, buf, ZZZLEN);
  118.     Close(f);
  119.  
  120.     DeleteFile(SIGNAME);    /* Avoids the copy error :-) */
  121.  
  122.     return 0;
  123. }
  124.